// 锁的封装
#pragma once
#include <iostream>
#include <pthread.h>

using namespace std;

// 实现自动的加锁解锁

class Mutex // 外部传入锁
{

public:
    Mutex(pthread_mutex_t *pmutex) : _pmutex(pmutex)
    {
    }
    void lock()
    {
        pthread_mutex_lock(_pmutex);
    }
    void unlock()
    {
        pthread_mutex_unlock(_pmutex);
    }
    ~Mutex() {}

private:
    pthread_mutex_t *_pmutex;
};

class Lockguard
{
public:
    Lockguard(pthread_mutex_t *mutex) : _tex(mutex)
    {
        _tex.lock();
    }
    ~Lockguard()
    {
        _tex.unlock();
    }

private:
    Mutex _tex;
};